package plantshop.tests;

import static org.junit.Assert.*;

import java.util.Map;

import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;

import plantshop.model.Display;
import plantshop.model.DisplayIterator;
import plantshop.model.Location;
import plantshop.model.plants.Aster;
import plantshop.model.plants.BurningBush;
import plantshop.model.plants.Plant;
import plantshop.model.plants.WhiteOak;

public class DisplayTest
{

	@BeforeClass
	public static void setUpBeforeClass() throws Exception
	{
	}

	@AfterClass
	public static void tearDownAfterClass() throws Exception
	{
	}

	@Before
	public void setUp() throws Exception
	{
	}

	@After
	public void tearDown() throws Exception
	{
	}

	@Test
	public void testSetTopLeft()
	{
		Display d = new Display(4, 400, 400, true, 1, 1);
		d.setTopLeft(new Location(1234, 5678));
		assertEquals(new Location(1234, 5678), d.getTopLeft());
	}

	@Test
	public void testSetBottomRight()
	{
		Display d = new Display(4, 400, 400, true, 1, 1);
		d.setBottomRight(new Location(1234, 5678));
		assertEquals(new Location(1234, 5678), d.getBottomRight());
	}

	@Test
	public void testSetRows()
	{
		Display d = new Display(4, 400, 400, true, 1, 1);
		d.setRows(3);
		assertEquals(3, d.getRows());
	}

	@Test
	public void testSetColumns()
	{
		Display d = new Display(4, 400, 400, true, 1, 1);
		d.setColumns(3);
		assertEquals(3, d.getColumns());
	}

	@Test
	public void testGetTopLeft()
	{
		Display d = new Display(4, 400, 400, true, 1, 1);
		assertEquals(new Location(400, 400), d.getTopLeft());
	}

	@Test
	public void testGetBottomRight()
	{
		Display d = new Display(4, 400, 400, true, 1, 1);
		assertEquals(new Location(570, 570), d.getBottomRight());
	}

	@Test
	public void testGetRows()
	{
		Display d = new Display(4, 400, 400, true, 1, 1);
		assertEquals(2, d.getRows());
	}

	@Test
	public void testGetColumns()
	{
		Display d = new Display(4, 400, 400, true, 1, 1);
		assertEquals(2, d.getColumns());
	}

	@Test
	public void testIterator()
	{
		Display d = new Display(4, 400, 400, true, 1, 1);
		assertTrue(d.iterator() instanceof DisplayIterator);
	}

	@Test
	public void testAddPlant()
	{
		Display d = new Display(4, 400, 400, true, 1, 1);
		Plant p = new Aster();
		d.addPlant(0, p);
		d.addPlant(1, p);
		for(Plant plant : d)
		{
			assertEquals(p, plant);
		}
	}

	@Test
	public void testGetPlant()
	{
		Display d = new Display(4, 400, 400, true, 1, 1);
		Plant p = new Aster();
		d.addPlant(0, p);
		assertEquals(p, d.getPlant(0));
		assertEquals(null, d.getPlant(1));
	}

	@Test
	public void testRemovePlant()
	{
		Display d = new Display(4, 400, 400, true, 1, 1);
		Plant p = new Aster();
		d.addPlant(0, p);
		d.addPlant(1, p);
		d.removePlant(0);
		assertEquals(null, d.getPlant(0));
	}

	@Test
	public void testSetPlant()
	{
		Display d = new Display(4, 400, 400, true, 1, 1);
		Plant p = new Aster();
		d.setPlant(0, p);
		d.setPlant(1, p);
		assertEquals(p, d.getPlant(0));
		assertEquals(p, d.getPlant(1));
	}

	@Test
	public void testGetPlantCounts()
	{
		Display d = new Display(10, 400, 400, true, 1, 1);
		Plant aster = new Aster();
		Plant burningBush = new BurningBush();
		Plant whiteOak = new WhiteOak();
		d.addPlant(0, aster);
		d.addPlant(1, aster);
		d.addPlant(2, burningBush);
		d.addPlant(4, whiteOak);
		d.addPlant(5, burningBush);
		
		Map<Plant, Integer> counts = d.getPlantCounts();
		
		assertEquals(new Integer(2), counts.get(aster));
		assertEquals(new Integer(2), counts.get(burningBush));
		assertEquals(new Integer(1), counts.get(whiteOak));
	}

	@Test
	public void testSize()
	{
		Display d = new Display(10, 400, 400, true, 1, 1);
		Plant aster = new Aster();
		Plant burningBush = new BurningBush();
		Plant whiteOak = new WhiteOak();
		d.addPlant(0, aster);
		d.addPlant(1, aster);
		d.addPlant(2, burningBush);
		d.addPlant(4, whiteOak);
		d.addPlant(5, burningBush);
		assertEquals(10, d.size());
	}

}
